package org.oschina.api.user.mail.queue;

import org.oschina.Constants;
import org.oschina.api.user.mail.UserMailType;
import org.oschina.api.user.mail.model.UserMail;
import org.oschina.helper.messagequeue.IMessageQueueHelper;
import org.oschina.queue.BaseQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 用户邮件推送队列
 */
@Component
public class UserMailPushQueue extends BaseQueue {

	@Autowired
	private IMessageQueueHelper messageQueueHelper;
	
	@Scheduled(fixedDelay=1000)
	private synchronized void handle()
	{
		UserMail userMail=(UserMail)get(Constants.QUEUE_USER_MAIL_PUSH, UserMail.class);
		if(userMail==null)
			return;
		
		if(userMail.getType().equals(UserMailType.SYSTEM))
			messageQueueHelper.send(Constants.QUEUE_USER_SYSTEM_MAIL_PUSH,userMail);
		else
			messageQueueHelper.send(Constants.QUEUE_USER_SIMPLE_MAIL_PUSH,userMail);
	}
}